﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace CodeStudy.WPF.Model
{
    public class PopulationStatistics
    {
        public string UnitName { get; set; }

        public int Population { get; set; }
    }

    /// <summary>
    /// Chart Data Provider Base Class
    /// </summary>
    /// <typeparam name="T">The type of data</typeparam>
    public abstract class ChartDataProvider<T>
    {
        public List<T> Data { get; protected set; }

        public ChartDataProvider(List<T> data)
        {
            this.Data = data;
            this.InitializeDataSeriesAndItemNames();
        }

        public string[] ItemNames { get; protected set; }

        public abstract void InitializeDataSeriesAndItemNames();

    }


    public class PopulationChartDataProvider : ChartDataProvider<PopulationStatistics>
    {
        public DoubleCollection PopulationSeries { get; protected set; }

        public PopulationChartDataProvider(List<PopulationStatistics> data) : base(data) { }

        public override void InitializeDataSeriesAndItemNames()
        {
            string[] names = new string[this.Data.Count];
            DoubleCollection population = new DoubleCollection();

            for (int i = 0; i < this.Data.Count; i++)
            {
                names[i] = this.Data[i].UnitName;
                population.Add(this.Data[i].Population);
            }

            this.ItemNames = names;
            this.PopulationSeries = population;
        }
    }
}
